<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt" style="width: 100%">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">选择仓库：</label>
                  <div class="layui-input-inline mr0">
                    <select id="queryWarehouseFactoryAdministrationId" name="warehouseFactoryAdministrationId" lay-filter="warehouseFactoryAdministrationId" lay-search></select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">客户名称：</label>
                  <div class="layui-input-inline mr0">
<!--                    <input name="customerName" class="layui-input" type="text"-->
<!--                           placeholder="请输入客户名称"/>-->
                    <select id="warehouseCustomerId" name="customerId" lay-filter="customerId"></select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">签收状态：</label>
                  <div class="layui-input-inline mr0">
                    <!-- 0 待受理 1 已受理 2 发货中 3 入库完成 -->
                    <select name="status" lay-filter="status">
                      <option value="">请选择</option>
                      <option value="0">待受理</option>
                      <option value="1">已受理</option>
                      <option value="2">发货中</option>
                      <option value="3">入库完成</option>
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">签收记录单号：</label>
                  <!-- <input type="text" name="SignInRecordId" id="SignInRecordId" hidden /> -->
                  <div class="layui-input-inline mr0">
                    <input name="SignInRecordName" class="layui-input" type="text" placeholder="请输入签收记录单号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">所属托管单编号：</label>
                  <div class="layui-input-inline mr0">
                    <input name="warehouseOrderCode" class="layui-input" type="text" placeholder="所属托管单编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物流单号：</label>
                  <div class="layui-input-inline mr0">
                    <input name="waybill" class="layui-input" type="text" placeholder="物流单号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">捆包号：</label>
                  <div class="layui-input-inline mr0">
                    <input name="userBundleCode" class="layui-input" type="text" placeholder="捆包号" />
                  </div>
                </div>

              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button id="purchaseSignTaskBtnAdd" class="layui-btn icon-btn color-reseda">添加入库作业记录</button>
            </div>
            <div class="lay-btn-rt"></div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="purchaseSignTaskTable" lay-filter="purchaseSignTaskTable"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="purchaseSignTaskTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view" style="background-color: #00B83F;color: white">详情</a>

  <!--  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>-->
  <!--  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="purchaseSignTaskForm">
  <form lay-filter="purchaseSignTaskForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <input name="id" type="hidden" />
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">所属运单号</label>
            <input type="text" name="waybillNum" id="waybillNum" hidden />
            <div class="layui-input-block" style="margin-left: 130px">
              <select id="waybill" name="waybill" lay-filter="waybill" lay-search lay-verify="required"></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">质检记录编号</label>
            <input type="text" name="productName" id="productName" hidden />
            <div class="layui-input-block" style="margin-left: 130px">
              <div id="standardSku" style="display: flex; align-items: center">
                <select id="warehouseProductId" name="warehouseProductId" lay-filter="warehouseProductId" lay-search></select>
              </div>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">入库类型</label>
            <!-- <input type="text" name="SignInRecordId" id="SignInRecordId" hidden /> -->
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="SignInRecordName" id="SignInRecordName" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">所属托管订单号</label>
            <input type="text" name="warehouseOrderId" id="warehouseOrderId" hidden />
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="warehouseOrderCode" id="warehouseOrderCode" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">所属客户</label>
            <input type="text" name="customerId" id="customerId" hidden />
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="customerName" id="customerName" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">规格号</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="productSpecCode" id="productSpecCode" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">品种</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="productVarietyName" id="productVarietyName" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">牌号</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="productMarkName" id="productMarkName" class="layui-input" disabled lay-verify="required" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">入库仓库</label>
            <input type="text" name="warehouseFactoryAdministrationName" id="warehouseFactoryAdministrationName" hidden />

            <div class="layui-input-block" style="margin-left: 130px">
              <select
                id="warehouseFactoryAdministrationId"
                name="warehouseFactoryAdministrationId"
                lay-filter="warehouseFactoryAdministrationId"
                lay-search
                lay-verify="required"></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">已有库存</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <input type="text" name="inventorySum" id="inventorySum" class="layui-input" disabled />
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div>
            <div class="layui-btn" id="addProduct" style="margin-top: 10px;">新增库位</div>
            <div id="productList">
              <table class="layui-table" id="purchaseSignTaskProductTable" lay-filter="purchaseSignTaskProductTable"></table>
            </div>
          </div>
        </div>

        <!--        <div class="open-details-title" style="margin-bottom: 5px;">库位信息</div>-->
        <!--        {{# if(d.eventName!="detail"){ }}-->
        <!--        <button class="layui-btn" id="addTableData" style="margin-top: 15px;">添加库位</button>-->
        <!--        {{# } }}-->
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="purchaseSignTaskFormSubmit" lay-submit>提交</button>
      </div>
    </div>
  </form>
</script>

<!--产品SKU编号下拉框-->
<script type="text/html" id="transportModeTemplate">
  <form class="layui-form model-form" style="padding: 0;">
    <select name="transportMode" id="distCode" lay-filter="distCode" lay-verify="required"></select>
  </form>
</script>

<!--发货物料-->
<script type="text/html" id="purchaseSignTaskProductList">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料编号：</label>
                    <div class="layui-input-inline mr0">
                      <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料名称：</label>
                    <div class="layui-input-inline mr0">
                      <input name="productName" class="layui-input" type="text" placeholder="请输入物料名称" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn color-green" lay-filter="deliveryRecordProductFormSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="deliveryRecordProductResets" lay-submit>重置</button>
                    <button class="layui-btn layui-btn-normal icon-btn" id="confirmChoose">确认选择</button>
                  </div>
                </div>
                <div class="query-rt"></div>
              </div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="purchaseSignTaskProductListTable" lay-filter="purchaseSignTaskProductListTable"></table>
      </div>
    </div>
  </div>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="purchaseSignTaskProductTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">入库</a>
</script>

<!-- 详情弹窗 -->
<script type="text/html" id="purchaseSignTaskView">
  <form lay-filter="purchaseSignTaskView" class="layui-form model-form">
    <input name="id" type="hidden" />
    <div class="layui-col-xs3">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">入库作业单编号</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="storageRecordCode" disabled class="layui-input" />
        </div>
      </div>
    </div>
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">入库类型</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="inventoryTypeName" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">运单编号</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="waybill" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">所属托管订单</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="warehouseOrderId" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">产品编号</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="warehouseProductId" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">产品类型</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="warehouseProductType" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-col-xs3">-->
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label" style="width: 100px;">单位</label>-->
<!--        <div class="layui-input-block" style="margin-left: 130px;">-->
<!--          <input type="text" name="unit" disabled class="layui-input" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
    <div class="layui-col-xs3">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">入库数量</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="inventoryQuantity" disabled class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs3" id="plateNoDetailDiv" style="display: none">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">入库仓库</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="warehouseFactoryAdministrationName" disabled class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs3" id="courierNoDetailDiv" style="display: none">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">入库库位</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="warehouseFactoryShelfSpaceName" disabled class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs3">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">作业人</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="creatorName" disabled class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs3">
      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px;">入库时间</label>
        <div class="layui-input-block" style="margin-left: 130px;">
          <input type="text" name="createTime" disabled class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div style="margin-left: 30px;">
        <table class="layui-table" id="purchaseSignTaskDetailTable" lay-filter="purchaseSignTaskDetailTable"></table>
      </div>
    </div>
  </form>
</script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;

    //列表
    admin.initDataSelect("warehouse/warehouse/admin/administration/list", { limit: 9999 }, "queryWarehouseFactoryAdministrationId", null, "仓库", "name", null);
    admin.initDataSelect("enterprise/sell/admin/customersInfo/list", { limit: 99999 }, "warehouseCustomerId", null, "客户", "customerName", null);

    //运输方式
    // admin.getDictList("queryTransportMode","transport_mode", null, "客户");

    // 渲染表格
    var insTb = table.render({
      elem: "#purchaseSignTaskTable",
      url: config.base + "warehouse/warehouse/finishedProductStorageRecord/list",
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号", width: 70 },
          { field: "storageRecordCode", align: "center", title: "入库作业编号", width: 120 },
          // { field: "storageRecordType", align: "center", title: "入库作业类型", width: 120 },
          { field: "qualityTestingCode", align: "center", title: "质检记录编号", width: 200 },
          { field: "processingReportCode", align: "center", title: "所属报工编号" },
          { field: "schedulingPlanDetailCode", align: "center", title: "所属制造令", width: 200 },
          {field: "customerName", align: "center", title: "客户名称"},
          // {field: "userBundleCode", align: "center", title: "捆包号"},
          // { field: "warehouseProductId", align: "center", title: "成品料号" },
          // { field: "productSpecCode", align: "center", title: "成品规格" },
          // { field: "warehouseProductType", align: "center", title: "成品类型" },
          // { field: "unit", align: "center", title: "单位" },
          { field: "inventoryQuantity", align: "center", title: "入库数量" },
          { field: "warehouseFactoryAdministrationName", align: "center", title: "入库仓库" },
          // { field: "warehouseFactoryShelfSpaceName", align: "center", title: "入库库位" },
          { field: "creatorName", align: "center", title: "作业人" },
          { field: "createTime", align: "center", title: "入库时间" },
          { align: "center", toolbar: "#purchaseSignTaskTableBar", title: "操作", width: 200, fixed: "right" }
        ]
      ]
    });

    // 工具条点击事件
    table.on("tool(purchaseSignTaskTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "edit") {
        //修改
        showEditModel(data);
        console.log(123);
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "view") {
        // 详情
        // showViewModel(data);
        admin.req(
          "warehouse/warehouse/storageRecord/selectStorageRecordDetail",
          {
            id: data.id
          },
          (res) => {
            showViewModel(res.data);
          }
        );
      }
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".lay-header").find("select").val("");
      $(".lay-header").find("input").val("");
      let field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
    });

    //监听排序
    table.on("sort(purchaseSignTaskTable)", function (obj) {
      table.reload("purchaseSignTaskTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 添加按钮点击事件
    $("#purchaseSignTaskBtnAdd").click(function () {
      // showEditModel();
      admin.formOpen({
        area: "90%",
        offset: "10%",
        title: "添加入库作业记录",
        path: "components/warehouse/product/warehouseFinishedProductStorageRecordFormByAdd.html",
        success: function () {}
      });
    });
    // 显示编辑弹窗
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: ["80%", "90%"],
        offset: ["8%", "15%"],
        title: data ? "修改入库作业记录" : "添加入库作业记录",
        content: $("#purchaseSignTaskForm").html(),
        success: async function () {
          //

          // 获取第一个弹窗中的多个字段
          var formData = {};
          //所属运单编号列表
          await admin.initDataSelectPro(
            "warehouse/warehouse/signOrder/list",
            {
              limit: 999
              // shipmentOrderStatus: '2',
            },
            "waybill",
            "所属运单编号",
            async (d, obj) => {
              $("#warehouseProductId").empty();
              form.val("purchaseSignTaskForm", {
                // SignInRecordName: obj.SignInRecordName,
                // warehouseOrderCode: obj.warehouseOrderCode,
                signInRecordId: "",
                SignInRecordName: "",
                warehouseOrderCode: "",
                customerName: "",
                customerId: ""
              });
              if (d.value) {
                form.val("purchaseSignTaskForm", {
                  // SignInRecordName: obj.SignInRecordName,
                  // warehouseOrderCode: obj.warehouseOrderCode,
                  signInRecordId: obj.id,
                  SignInRecordName: obj.shipmentOrderCode,
                  warehouseOrderCode: obj.orderCode,
                  customerName: obj.customerName,
                  customerId: obj.customerId
                });
                await admin.initDataSelectPro(
                  "warehouse/warehouse/product/selectProduct",
                  {
                    limit: 999,
                    warehouseSignsOrderId: d.value
                  },
                  "warehouseProductId",
                  "产品SKU编号",
                  (d, obj) => {
                    form.val("purchaseSignTaskForm", {
                      productSpecCode: "",
                      productVarietyName: "",
                      productMarkName: ""
                    });

                    form.val("purchaseSignTaskForm", {
                      // ...obj,
                      productSpecCode: obj.productSpecCode,
                      productVarietyName: obj.productVariety,
                      productMarkName: obj.productMark
                    });
                    // setLocationTable();
                    //  formData["warehouseProductId"] = obj.warehouseProductId;
                    //  formData["productSpecCode"] = obj.productSpecCode;
                    //  formData["productVarietyName"] = obj.productVariety;
                    //  formData["productMarkName"] = obj.productMark;
                    //  formData["name"] = obj.name;
                  },
                  "productCode"
                );
              }
            },
            "waybill"
          );

          //入库仓库
          await admin.initDataSelectPro(
            "warehouse/warehouse/admin/administration/selectAll",
            {
              limit: 999
              // customerId: '2',
            },
            "warehouseFactoryAdministrationId",
            "入库仓库",
            async (d, obj) => {
              form.val("purchaseSignTaskForm", {
                inventorySum: "",
                warehouseFactoryAdministrationName: ""
              });
              table.reload("purchaseSignTaskProductTable", { data: [] });
              if (d.value) {
                form.val("purchaseSignTaskForm", {
                  inventorySum: obj.inventorySum,
                  warehouseFactoryAdministrationName: obj.name
                });
                table.reload("purchaseSignTaskProductTable", { data: obj.warehouseFactoryShelfSpaceVOList });
                admin.req(
                  "warehouse/admin/warehouseFactoryArea/list",
                  {
                    warehouseId: d.value
                  },
                  (res) => {
                    console.log("res", res);
                  }
                );
              }
            },
            "name"
          );

          if (data) {
            if (data.transportMode == 0) {
              $("#plateNoDiv").show();
              $("#courierNoDiv").hide();
            } else {
              $("#plateNoDiv").hide();
              $("#courierNoDiv").show();
            }
          }

          //运输方式选择事件
          form.on("select(transportMode)", function (selectData) {
            if (selectData.value == 0) {
              $("#plateNoDiv").show();
              $("#courierNoDiv").hide();
            } else if (selectData.value == 1) {
              $("#plateNoDiv").hide();
              $("#courierNoDiv").show();
            }
          });

          //发货数量验证
          form.verify({
            quantity: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
            compare: function (data, item) {
              var quantity = Number($(item).parent().parent().parent().prev().find("div").text());
              if (quantity < Number(data)) {
                return "发货数量不能大于剩余发货数！";
              }
            }
          });

          var codeArr = [];
          var deliveryRecordProductList = [];

          // 添加发货物料
          $("#addProduct").click(function () {
            // var warehouseFactoryAdministrationId = $("form select[name='warehouseFactoryAdministrationId']").val();
            // if(warehouseFactoryAdministrationId){
            var purchaseSignTaskProductList = admin.open({
              type: 1,
              area: ["80%", "85%"],
              offset: ["10%", "17%"],
              title: "物料列表",
              content: $("#purchaseSignTaskProductList").html(),
              success: function () {
                var codes = "";
                for (var i = 0; i < codeArr.length; i++) {
                  if (i == 0) {
                    codes = '"' + codeArr[i] + '"';
                  } else {
                    codes += "," + '"' + codeArr[i] + '"';
                  }
                }
                // 渲染表格
                var insTb = table.render({
                  elem: "#purchaseSignTaskProductListTable",
                  url: config.base + "enterprise/purchase/admin/purchaseOrderDetail/list",
                  // where: {warehouseFactoryAdministrationId: warehouseFactoryAdministrationId, filterDeliveryComplete: 1, codes: codes},
                  page: false,
                  cellMinWidth: 100,
                  cols: [
                    [
                      { type: "checkbox" },
                      { field: "id", align: "center", title: "ID", hide: "true" },
                      { field: "skuCode", align: "center", title: "物料编号", width: 160 },
                      { field: "productName", align: "center", title: "物料名称", width: 160 },
                      { field: "specifications", align: "center", title: "规格型号", width: 160 },
                      { field: "quantity", align: "center", title: "数量" },
                      { field: "unitName", align: "center", title: "计量单位", width: 100 },
                      { field: "rate", align: "center", title: "税率(%)" },
                      { field: "taxPrice", align: "center", title: "含税单价" },
                      { field: "price", align: "center", title: "单价" },
                      { field: "amount", align: "center", title: "金额" },
                      { field: "tax", align: "center", title: "税额" },
                      { field: "totalAmount", align: "center", title: "合计金额" }
                    ]
                  ]
                });

                // 搜索
                form.on("submit(deliveryRecordProductFormSubSearchLog)", function (data) {
                  insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
                });

                // 重置搜索
                form.on("submit(deliveryRecordProductResets)", function (data) {
                  $(".lay-header").find("select").val("");
                  $(".lay-header").find("input").val("");
                  let field = data.field;
                  for (let key in field) {
                    field[key] = "";
                  }
                  insTb.reload({ where: field, page: { curr: 1 } }, "data");
                });

                // 确认选择
                $("#confirmChoose").click(function () {
                  var checkStatus = table.checkStatus("purchaseSignTaskProductListTable"); //test即为基础参数id对应的值
                  var dataS = checkStatus.data;
                  if (dataS.length == 0) {
                    layer.msg("请选择库位", { icon: 2, time: 1000 });
                  } else {
                    for (var i = 0; i < dataS.length; i++) {
                      dataS[i].purchaseOrderDetailId = dataS[i].id;
                      deliveryRecordProductList.push(dataS[i]);
                      codeArr.push(dataS[i].skuCode);
                    }
                    layer.close(purchaseSignTaskProductList);
                    // 获取数据集合并传入表格中
                    table.reload("purchaseSignTaskProductTable", {
                      data: deliveryRecordProductList,
                      limit: deliveryRecordProductList.length
                    });
                  }
                });
              }
            });
            // }else{
            //   layer.msg('请选择采购订单!', {icon : 2, time : 1000});
            // }
          });

          // if(data){
          //   data.purchaseDeliveryRecordProductList.forEach(purchaseDeliveryRecordProduct=>{
          //     purchaseDeliveryRecordProduct.hasDeliveryQuantity = purchaseDeliveryRecordProduct.hasSignQuantity;
          //     purchaseDeliveryRecordProduct.deliveryQuantity = purchaseDeliveryRecordProduct.quantity;
          //     purchaseDeliveryRecordProduct.quantity = purchaseDeliveryRecordProduct.purchaseQuantity;
          //     codeArr.push(purchaseDeliveryRecordProduct.skuCode);
          //     deliveryRecordProductList.push(purchaseDeliveryRecordProduct);
          //   })
          // }

          // //渲染表格
          var insTb = table.render({
            elem: "#purchaseSignTaskProductTable",
            data: data ? data.purchaseDeliveryRecordProductList : [deliveryRecordProductList],
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号", height: 50 },
                { field: "code", align: "center", title: "所在库位" },
                { field: "warehouseAreaCode", align: "center", title: "所在库区" },
                { field: "inventorySum", align: "center", title: "当前库存" },
                { align: "center", toolbar: "#purchaseSignTaskProductTableBar", title: "操作", width: 100 }
              ]
            ]
          });

          // 工具条点击事件
          table.on("tool(purchaseSignTaskProductTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "edit") {
              // 入库
              showEditModel(data);
            }
          });

          // 入库操作
          function showEditModel(data) {
            admin.formOpen({
              type: 1,
              area: "80%",
              offset: "5%",
              title: "入库作业",
              path: "components/warehouse/product/warehouseStorageRecordForm.html",
              success: function () {
                // form.val('warehouseForm', {...data,...formData});
                console.log("parentData", parentData);
                let obj = {
                  waybillNum: $("#waybillNum").val(),
                  warehouseProductId: $("#warehouseProductId").val(),
                  inventorySum: $("#inventorySum").val(),
                  warehouseOrderCode: $("#warehouseOrderCode").val(),
                  SignInRecordName: $("#SignInRecordName").val(),
                  customerName: $("#customerName").val(),
                  customerId: $("#customerId").val(),
                  productSpecCode: $("#productSpecCode").val(),
                  productVarietyName: $("#productVarietyName").val(),
                  productMarkName: $("#productMarkName").val(),
                  warehouseFactoryAdministrationName: $("#warehouseFactoryAdministrationName").val(),
                  name: $("#name").val(),
                  signInRecordId: $("#signInRecordId").val()
                };
                console.log("obj", obj);
                parentData.data = obj;
                // parentData.formData = formData;

                // // 表单提交事件
                // form.on('submit(warehouseFormSubmit)', function (d) {
                //   layer.load(2);
                //   admin.req('warehouse/warehouse/storageRecord/add' , JSON.stringify(d.field), function (res) {
                //     layer.closeAll('loading');
                //     if (res.code == 200) {
                //       layer.msg(res.msg, {icon: 1});
                //       table.reload('warehouseTable');
                //       layer.closeAll('page');
                //     } else {
                //       layer.msg(res.msg, {icon: 2});
                //     }
                //   }, data ? 'PUT' : 'POST',true,"application/json;charset=utf-8");
                //   return false;
                // });
              }
            });
          }

          form.val("purchaseSignTaskForm", data);
          // 表单提交事件
          form.on("submit(purchaseSignTaskFormSubmit)", function (d) {
            var purchaseDeliveryRecordProducts = [];
            $("#productList")
              .find("tbody tr")
              .each(function (index, item) {
                var purchaseDeliveryRecordProduct = {};
                $(item)
                  .find("td")
                  .each(function (tdIndex, tdItem) {
                    if ($(tdItem).data("field") == "purchaseOrderDetailId") {
                      purchaseDeliveryRecordProduct.purchaseOrderDetailId = $(tdItem).find("div").text();
                    }
                    if ($(tdItem).data("field") == "deliveryQuantity") {
                      purchaseDeliveryRecordProduct.quantity = $(tdItem).find("input").val();
                    }
                    if ($(tdItem).data("field") == "deliveryQuantity") {
                      purchaseDeliveryRecordProduct.quantity = $(tdItem).find("input").val();
                    }
                  });
                purchaseDeliveryRecordProducts.push(purchaseDeliveryRecordProduct);
              });
            // if(purchaseDeliveryRecordProducts.length > 0){
            layer.load(2);
            d.field.purchaseDeliveryRecordProducts = purchaseDeliveryRecordProducts;
            admin.req(
              data ? "warehouse/warehouse/storageRecord/update" : "warehouse/warehouse/storageRecord/add",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("purchaseSignTaskTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST",
              false,
              "application/json"
            );
            // }else{
            //   layer.msg("至少添加一条发货物料！", {icon: 2});
            // }
            return false;
          });
        }
      });
    }

    // 显示详情弹窗
    function showViewModel(data) {
      admin.open({
        type: 1,
        area: "80%",
        offset: ["10%", "16%"],
        title: "入库作业记录详情",
        content: $("#purchaseSignTaskView").html(),
        success: function () {
          //数据回显
          form.val("purchaseSignTaskView", data);
          // if (data.transportMode == 0) {
          //   $("#plateNoDetailDiv").show();
          //   $("#courierNoDetailDiv").hide();
          // } else {
          //   $("#plateNoDetailDiv").hide();
          //   $("#courierNoDetailDiv").show();
          // }

          // 渲染表格
          console.log("data",data);
            var insTb = table.render({
              elem: "#purchaseSignTaskDetailTable",
              // url: config.base + "warehouse/warehouse/finishedProductStorageRecord/selectStorageRecordDetai",
              // where: {id: data.id  },
              data:data.warehouseStorageOrderDetailList,
              page: false,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers", width: 80, title: "序号" },
                  // { field: "id", align: "center", title: "采购订单明细ID", hide: "true" },
                  { field: "areaName", align: "center", title: "所在库区" },
                  { field: "shelfSpaceLabelCode", align: "center", title: "所在库位" },
                  { field: "inventoryTypeName", align: "center", title: "入库类型" },
                  { field: "quantity", align: "center", title: "当前库存数" },
                  { field: "userBundleCode", align: "center", title: "捆包号" },
                  { field: "grossWeight", align: "center", title: "毛重" },
                  { field: "netWeight", align: "center", title: "净重" }
                ]
              ]
            });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "265px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/purchase/admin/purchaseDeliveryRecord/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    // 导出excel
    $("#purchaseSignTaskBtnExport").click(function () {
      var checkRows = table.checkStatus("purchaseSignTaskTable");
      if (checkRows.data.length == 0) {
        layer.msg("请选择要导出的数据", { icon: 2 });
      } else {
        table.exportFile(insTb.config.id, checkRows.data, "xls");
      }
    });
  });
</script>
